#include <cstdio>

__int64 f[ 35 ][ 35 ];
int n;
char map[ 35 ][ 35 ];

void init( )
{
    int i;
    for ( i = 0; i < n; i++ )
        scanf("%s", map[ i ]);
}

void work( )
{
    int i, j, k;
    for ( i = 0; i < n; i++ )
        for ( j = 0; j < n; j++ )
        {
            f[ i ][ j ] = 0;
            if ( i == 0 && j == 0 )
                f[ 0 ][ 0 ] = 1;
            for ( k = 0; k < j; k++ )
                if ( map[ i ][ k ] == j - k + '0' )
                    f[ i ][ j ] += f[ i ][ k ];
            for ( k = 0; k < i; k++ )
                if ( map[ k ][ j ] == i - k + '0' )
                    f[ i ][ j ] += f[ k ][ j ];
        }
    printf("%I64d\n", f[ n - 1 ][ n - 1 ]);
}

int main( )
{
    while ( scanf("%d", &n) && n != -1 )
    {
        init( );
        work( );
    }
    return 0;
}
